home *** CD-ROM | disk | FTP | other *** search
- ;-----------------------------------------------------------------------
- ; SetSound DA
- ; Copyright 1985 by William P. Steinberg
- ;
- ; SetSound is a small (0.6K) DA that sets the default sound volume
- ; Shrink & obscure courtesy Steve Brecher
- ; Original shell from MacUser issue #1, Bill Bond & Chris Allen
- ;
- ;---
- ; Version 1.0 = 1008 bytes
- ; Version 1.2 = 562 bytes
- ; Version 1.3 = put back autokey in accepted eventlist, though I ignore it
- ;-----------------------------------------------------------------------
-
- Resource 'DRVR' 31 'SetSound' 32
-
- INCLUDE Sys.D
-
- Macro Assume Cond =
- If {Cond}
- Else
- Error -- Assumption {Cond} is not true
- Endif
- |
-
- DAStart:
- DC.W $4400 ; Flags/descriptor
- ; (lock in memory, can respond to
- ; Control calls)
- DC.W 0 ; Tick Count
- DC.W 360 ; Event mask
- ; (will handle: keydown, autokey,
- ; mousedown, and activate)
- DC.W 0 ; Menu ID
- DC.W DAOpen-DAStart ; Offset to open routine
- DC.W DAPrime-DAStart ; Offset to prime routine
- DC.W DAControl-DAStart ; Offset to control routine
- DC.W DAStatus-DAStart ; Offset to status routine
- DC.W DAClose-DAStart ; Offset to close routine
- DC.B 8 ; Desk Accesory title
- DC.B 'SetSound' ; (This is optional - it only helps
- .ALIGN 2 ; to identify the DA in the heap.
- ; The DA appears in the Apple
- ; menu using the name of DRVR.)
-
- ; A6 offsets:
- ;
- DriverID EQU -2 ; Word
- DriverType EQU DriverID-4 ; Long
- DriverName EQU DriverType-256 ; 256 byte string buffer
-
- DAOpen:
- LINK A6,#DriverName
- MOVE.L (A5),A0 ; addr of QD globals
- Assume thePort = 0
- MOVE.L (A0),-(SP) ; save thePort on stack
- MOVE.L A1,A4 ; Put DCE pointer in A4
-
- MOVEQ #0,D3 ; assume already open, result = noErr
- TST.L dCtlWindow(A4) ; Does the window exist ?
- BNE.S OpenDone ; If yes, the DA was already opened
-
- LEA DAStart,A0 ; Get handle to the DA
- _RecoverHandle
- MOVE.L A0,-(SP) ; Get information about DA
- PEA DriverID(A6) ; DA id
- PEA DriverType(A6) ; DA type = 'DRVR'
- PEA DriverName(A6) ; DA name
- _GetResInfo
-
- SUBQ #4,SP ; Make room for result
- CLR.L -(SP) ; Create WindowRecord on the heap
- PEA WindowRect ; Push the address of the window's rect
- PEA DriverName(A6) ; Push the address of the window's title
- CLR -(SP) ; Make it invisible for now
- MOVE.W #noGrowDocProc,-(SP) ; Push the window definition id
- MOVEQ #-1,D0
- MOVE.L D0,-(SP) ; Window will appear in front
- MOVE.B D0,-(SP) ; Give it a goaway box
- CLR.L -(SP) ; Window reference value
- _NewWindow ; Create the window
- MOVEQ #OpenErr,D3 ; assume failure
- MOVE.L (SP)+,D1 ; Get the window pointer
- BEQ.S OpenDone
- LEA MyWindow,A0
- MOVE.L D1,(A0) ; Save the window pointer
- MOVE.L D1,A0
- MOVE.W dCtlRefNum(A4),windowKind(A0)
- MOVE.L A0,dCtlWindow(A4) ; Put the window pointer in the DCE
- MOVEQ #0,D3 ; Result = noErr
- OpenDone:
- _SetPort ;restore thePort
- UNLK A6
- MOVE.L D3,D0
- RTS
-
- DAClose:
- MOVE.L A1,A4 ; Put Device Control Entry in A4
- MOVE.L (A5),A0 ;addr of QD globals
- Assume thePort = 0
- MOVE.L (A0),-(SP) ;save thePort on stack
- CloseDA:
-
- MOVE.L WindowList,D0
- DAClose1:
- BEQ.S DAClose3
- CMP.L MyWindow,D0 ; Is this our window ?
- BEQ.S DAClose2
- MOVE.L D0,A0
- MOVE.L nextWindow(A0),D0 ; Get the next window in the chain
- BRA.S DAClose1
- DAClose2:
- MOVE.L D0,-(SP) ; Throw away our window
- _DisposWindow
- CLR.L dCtlWindow(A4) ; Window is gone, tell the DCE
- DAClose3:
- _SetPort
- Bra.S DAexit
-
- DAControl:
- MOVE.L A1,A4 ; Put pointer to DCE in A4
- MOVE.L (A5),A1 ;addr of QD globals
- Assume thePort = 0
- MOVE.L (A1),-(SP) ;save thePort on stack
-
- ; A0 points to the parameter block which tells us what we need
- ; to do and supplies us with the data to carry it out.
-
- MOVE csCode(A0),D0
-
- Assume GoodBye = -1
- ADDQ #1,D0
- BEQ.S CloseDA ; bye
- CMP.W #accEvent+1,D0 ; Event message from SystemEvent
- BNE.S CTLReturn
-
- CTLEvent:
- LEA SPVolCtl,A3 ;for later
- MOVE.L csParam(A0),A2
- MOVE.L MyWindow,-(SP)
- _SetPort
- Assume evtNum = 0
- CMP.W #keyDwnEvt,(A2) ; Keydown event
- BEQ EVTkeyDown
- CMP.W #updatEvt,(A2) ; Update event
- BEQ.S EVTupdateEvt
- CMP.W #activateEvt,(A2) ; Activate event
- BEQ.S EVTactivateEvt
- CTLReturn:
- _SetPort
- MOVE.L A4,A1 ; restore DCE ptr
- MOVE.L JIODone,-(SP) ; Goto IODone
- DAPrime:
- DAStatus:
- DAexit:
- CLR.W D0 ; Return code
- RTS
-
- EVTactivateEvt:
- LEA ActivePend,A0
- MOVE.B EvtMBut(A2),(A0) ; Low order byte of EvtMeta
- BRA.S CTLReturn
-
- EVTupdateEvt:
- MOVE.L MyWindow,A2
- MOVE.L A2,-(SP) ; for EndUpdate
- PEA portRect(A2) ; for EraseRect
- MOVE.L A2,-(SP)
- _BeginUpdate
- MOVE.B (A3),D0 ; SPVolCtl
- LEA Chars,A2
- AND.B (A2)+,D0 ; (#7) clr bits 3..15
- ADD.B (A2)+,D0 ; (#'0') Convert to ASCII
- LEA ASCIIVol,A3
- MOVE.B D0,(A3) ; set ASCII volume in message
- _EraseRect
- MOVE.W (A2)+,-(SP) ; space
- _DrawChar
- ST -(SP)
- _SetFontLock
- LEA Coords,A3
- MOVE.L (A3)+,-(SP)
- _MoveTo
- Assume SysFont = 0
- CLR.W -(SP)
- _TextFont
- MOVE.W (A2)+,-(SP) ;Copyright symbol
- _DrawChar
- MOVE.W #applFont,-(SP)
- _TextFont
- MOVEQ #0,D4
- MOVEQ #4-1,D3
- @0 MOVE.L A2,-(SP) ;msg addr
- _DrawString
- MOVE.L (A3)+,-(SP) ;next coords (note we do one
- _MoveTo ;superfluous MoveTo)
- MOVE.B (A2)+,D4 ;bump to next msg...
- ADD D4,A2
- DBRA D3,@0
- _EndUpdate
- CLR -(SP)
- _SetFontLock
- LEA ActivePend,A2
- BCLR #ActiveFlag,(A2)
- BEQ.S CtlReturn
- Beep: MOVE.W #3,-(SP) ; Beep on update at current level
- _SysBeep
- CtlRet BRA.S CTLReturn
-
- EVTkeyDown:
- CLR D2
- MOVE.B evtMessage+3(A2),D2
- SUB.B #'0',D2
- BMI.S CtlRet
- CMP.B #7,D2
- BGT.S CtlRet
-
- ANDI.B #$F8,(A3) ;SPCtlVol
- OR.B D2,(A3)
- LINK A1,#-(csParam+2)
- MOVE.L A1,A0
- MOVE D2,-(A0) ;csParam
- Assume csCode = csParam-2
- MOVE #2,-(A0) ;csCode
- Assume ioRefNum = csCode-2
- MOVE.W #-4,-(A0) ;sound drvr refnum
- MOVE.L SP,A0
- _Control,IMMED
- UNLK A1
- LEA SysParam,A0
- MOVEQ #-1,D0
- _WriteParam
- PEA NumberRect
- _InValRect
- Bra.S Beep
-
-
- MyWindow: DC.L 0 ; DA window pointer
- Coords: DC.L 20<<16!10, 35<<16!19, 50<<16!27, 65<<16!37
- WindowRect: DC.W 40,2,115,213 ; DA window rectangle
- NumberRect: DC.W 38,175,50,190 ; DA number rectangle for invalrect
- ActivePend: DC.W 0
- Chars: DC.B 7 ; Mask for SPVolCtl
- DC.B '0' ; Value to add to make ASCII
- DC.W ' ' ; <space> for setfontlock
- DC.W ' ©' ;copyright symbol
- DC.B 28,'1985 by William P. Steinberg'
- DC.B 28,'Vers 1.3 - Free Distribution'
- DC.B 23+1,'Current Volume Level = '
- ASCIIVol: DC.B 0
- DC.B 21,'Enter New Level (0-7)'
-
- END